package com.edu.whty.service.impl;



import com.edu.whty.dao.AttachFileDao;
import com.edu.whty.entity.base.AttachFile;
import com.edu.whty.service.AttachFileService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @desc 资源附件表Service实现类
 * @date 2014-5-7
 */
@Component("attachFileService")
public class AttachFileServiceImpl implements AttachFileService {

	private static final Logger LOGGER = LogManager.getLogger(AttachFileServiceImpl.class);


	@Resource
	private AttachFileDao attachFileDao;


	/**
	 * 新增
	 *
	 * @param attachFile
	 * @throws Exception
	 */
	@Override
	public Long addAttachFile(AttachFile attachFile) throws Exception {
		attachFileDao.insertOne(attachFile);
		return attachFile.getFid();
	}

	/**
	 * 修改
	 *
	 * @param attachFile
	 * @throws Exception
	 */
	@Override
	public void modAttachFile(AttachFile attachFile) throws Exception {
		attachFileDao.updateOne(attachFile);

	}


	/**
	 * 文件上传完成
	 *
	 * @param attachFile
	 * @return
	 * @throws Exception
	 */
	@Override
	public AttachFile uploadComplete(AttachFile attachFile) throws Exception {
		/** 更新附件为上传完成状态 */
		//final AttachFile attachFile = attachFileDao.selectOne(fid);
		attachFile.setPostedLength(attachFile.getFileLength());
		attachFile.setPostedPercent("100%");
		attachFile.setPostComplete("true");
		attachFile.setFilePos(attachFile.getFileLength());

		attachFileDao.updateOne(attachFile);


		return attachFile;
	}


	/**
	 * 根据主键查询附件
	 *
	 * @param fid
	 * @return
	 */
	@Override
	public AttachFile getAttachFile(Long fid)  {
		return attachFileDao.selectOne(fid);
	}


	/**
	 * 查询校园主机未同步到云端数据
	 * @param
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<AttachFile> getAttachFileIsLocal() throws Exception {
		return attachFileDao.getAttachFileIsLocal();
	}



	/**
	 * 查询云端未同步到校园主机数据
	 * @param
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<AttachFile> getAttachFileIsCloud() throws Exception {
		return attachFileDao.getAttachFileIsCloud();
	}




	@Override
	public List<AttachFile> getAttachFileByOrgId(String orgId) throws Exception {
		return attachFileDao.getAttachFileByOrgId(orgId);
	}


}
